package com.example.algorithm.controller;


import com.example.algorithm.algorithmService.*;
import com.example.algorithm.utils.GetDateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;


@RestController
@Slf4j
public class ControlAlgorithmcontroller {
    @Autowired
    private ControlAlgorithmService controlAlgorithmService;
    @Autowired
    private ControlPowerByMonthService controlPowerByMonthService;
    @Autowired
    private InspectorSceneService inspectorSceneService;
    @Autowired
    private DataService dataService;
    @Autowired
    private IsActiveService activeService;

    @RequestMapping("/getControlMark")
    // public void getControlMark(String startDate,String endDate)  {
    public void getControlMark() {
        String startDate = "2021/11/03";
        String endDate = "2021/11/03";
        try {
            long start = System.currentTimeMillis(); // 开始时间

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
            Date parseStartDate = sdf.parse(startDate);
            Date parseEndDate = sdf.parse(endDate);
            int num = GetDateUtils.differentDay(parseStartDate, parseEndDate);
           //dataService.getData();
          controlAlgorithmService.getControlMarkByDate(startDate, num);
          controlAlgorithmService.getResult();
            // inspectorSceneService.getInspectorSceneIndex(startDate, num);
            long end = System.currentTimeMillis(); // 结束时间

            System.out.println("毫秒：" + (end - start)); // 程序执行时间
        } catch (Exception e) {
            e.printStackTrace();
            log.error("===>计算问题清单指数异常, startDate: {}, endDate: {}, e: {}", startDate, endDate, e.getMessage());
            //      return "error";
        }
        //  return "ok";
    }

    /**
     * 为表sv_yd_screen_v2中的所有数据添加主被动
     */
    @RequestMapping("addActive")
    private void addActive(){
        long start = System.currentTimeMillis(); // 开始时间
        try {
            activeService.addActive();
            System.out.println("添加成功");
        } catch (Exception e) {
            System.out.println("失败");
        }
        long end = System.currentTimeMillis();//结束时间

        System.out.println("运行时间 "+(end-start)+" 毫秒");
    }

}